﻿using System;
using System.Collections.Generic;
using System.Text;

namespace hedefgrup.reports.common
{
    public class Criteria_Organization : Criteria
    {
        public const string AllOrganizations = "Toplam";
        public const string Renault = "Renault";
        public const string Dacia = "Dacia";

        private static readonly List<string> allOrganizations = new List<string>(new string[] { AllOrganizations, Renault, Dacia });

        public Criteria_Organization()
        {
            Values.Add(AllOrganizations);
        }

        public override string Name
        {
            get
            {
                return "Organization";
            }
        }

        public override string[] GetValueList()
        {
            return allOrganizations.ToArray();
        }

        public override string ToSqlStatementFilter(ref int parameterOffset)
        {
            switch (Value)
            {
                case AllOrganizations:
                default:
                    return Context.Report.DealerColumn + " IN (SELECT [Key] FROM Tree WHERE [Path] LIKE '" + Context.Organization.Path + "%')";
                case Renault:
                case Dacia:
                    return "MARKA = @p_" + parameterOffset++ + " AND " + Context.Report.DealerColumn +
                        " IN (SELECT [Key] FROM Tree WHERE [Path] LIKE '" + Context.Organization.Path + "%')";
            }
        }

        public override Type ValueType
        {
            get { return typeof(string); }
        }

        public override string Expression
        {
            get { throw new NotImplementedException(); }
        }

        public override string Operator
        {
            get { throw new NotImplementedException(); }
        }
    }
}
